package com.whsr.readservice.controller;

import com.github.pagehelper.PageInfo;
import com.whsr.readservice.service.ChapterContentService;
import com.whsr.readservice.service.ChapterService;
import com.whsr.readservice.util.ResultUtil;
import com.whsr.readservice.vo.Chapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/server/chaptercontent")
public class ChapterContentController {

    @Autowired
    private ChapterContentService chapterContentService;

    /**
     * 根据书号 下载作品目录
     * @param bookIds
     * @return
     */
    @RequestMapping(value = "/inserchapters2",method = RequestMethod.POST)
    public int inserChapters2(@RequestBody List<String> bookIds){
        return chapterContentService.insertChapters2(bookIds);
    }

    /**
     * 根据书号和章节号 查询章节内容
     * @param bookId
     * @return
     */
    @RequestMapping(value = "/queryChContentByApp/{bookId}/{chId}",method = RequestMethod.GET)
    public Map<String, Object> getChapters(@PathVariable Integer bookId, @PathVariable Integer chId){
        try {
            return chapterContentService.getContentByBookIdAndChId(bookId, chId);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.getResultByError();
        }
    }
}
